<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置我的密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/adminstatic/base/base.css"/>
    <script src="/adminstatic/base/baseCss.js"></script>
    <style type="text/css">
        .layui-form-label {
            width: 120px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="">
                        <input type="hidden" name="id" value="<%=id%>"/>
                        <div class="layui-form-item">
                            <label class="layui-form-label">当前密码</label>
                            <div class="layui-input-inline">
                                <label>
                                    <input type="password" name="oldPassword"
                                           class="layui-input">
                                </label>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="newPassword"
                                       class="layui-input">

                            </div>
                            <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认新密码</label>
                            <div class="layui-input-inline">
                                <label>
                                    <input type="password" name="confirmPassword"
                                           class="layui-input">
                                </label>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button id="submitBtn" class="layui-btn" lay-submit lay-filter="setmypass">确认修改</button>
                            </div>
                        </div>

                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/adminstatic/base/base.js"></script>
<script type="application/javascript">
    $("#submitBtn").click(function () {
        var id = $("input[name='id']").val();
        console.log(id)
        var oldPassword = $("input[name='oldPassword']").val();
        if (!vaildeParam(oldPassword)) {
            layer.msg('当前密码不能为空', {icon: 5});
            return;
        }

        var newPassword = $("input[name='newPassword']").val();
        if (!vaildeParam(newPassword)) {
            layer.msg('新密码不能为空', {icon: 5});
            return;
        } else if (vaildeParam(newPassword) && (newPassword.length < 6 || newPassword.length > 17)) {
            layer.msg('密码长度范围在6~16位之间', {icon: 5});
            return;
        }


        var confirmPassword = $("input[name='confirmPassword']").val();
        if (!vaildeParam(confirmPassword)) {
            layer.msg('确认密码不能为空', {icon: 5});
            return;
        } else if (newPassword !== confirmPassword) {
            layer.msg('两次密码不正确', {icon: 5});
            return;
        }

        var api = '/admin/changePassword';
        var data = {
            "id": id,
            "oldPassword": oldPassword,
            "newPassword": newPassword
        }

        postJSON(api, data, function (res) {
            cleanSuccess(res)

        })

    })
</script>
</body>
</html>